home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 22 / CU Amiga Magazine's Super CD-ROM 22 (1998)(EMAP Images)(GB)[!][issue 1998-05].iso / PowerPC / Programming / PPCSmallEiffel / lib_se / manifest_array_pool.e < prev    next >
Encoding:
Text File  |  1998-01-16  |  4.0 KB  |  163 lines

  1. --          This file is part of SmallEiffel The GNU Eiffel Compiler.
  2. --          Copyright (C) 1994-98 LORIA - UHP - CRIN - INRIA - FRANCE
  3. --            Dominique COLNET and Suzanne COLLIN - colnet@loria.fr 
  4. --                       http://www.loria.fr/SmallEiffel
  5. -- SmallEiffel is  free  software;  you can  redistribute it and/or modify it 
  6. -- under the terms of the GNU General Public License as published by the Free
  7. -- Software  Foundation;  either  version  2, or (at your option)  any  later 
  8. -- version. SmallEiffel is distributed in the hope that it will be useful,but
  9. -- WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  10. -- or  FITNESS FOR A PARTICULAR PURPOSE.   See the GNU General Public License 
  11. -- for  more  details.  You  should  have  received a copy of the GNU General 
  12. -- Public  License  along  with  SmallEiffel;  see the file COPYING.  If not,
  13. -- write to the  Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  14. -- Boston, MA 02111-1307, USA.
  15. --
  16. class MANIFEST_ARRAY_POOL
  17.    --
  18.    -- Unique global object in charge of MANIFEST_ARRAY used.
  19.    --
  20.  
  21. inherit GLOBALS;
  22.  
  23. feature {NONE}
  24.    
  25.    manifest_array_types: DICTIONARY[TYPE,INTEGER] is
  26.      -- Gives the type for all kind of used MANIFEST_ARRAY.
  27.       once
  28.      !!Result.make;
  29.       end;
  30.  
  31.    us_se_ma: STRING is "se_ma";
  32.  
  33. feature {MANIFEST_ARRAY}
  34.  
  35.    c_call(ma_type: TYPE) is
  36.       require
  37.      small_eiffel.is_ready
  38.       local
  39.      id: INTEGER;
  40.       do
  41.      id := ma_type.id;
  42.      if not manifest_array_types.has(id) then
  43.         manifest_array_types.put(ma_type,id);
  44.      end;
  45.      cpp.put_string(us_se_ma);
  46.      cpp.put_integer(id);
  47.       end;
  48.  
  49. feature {C_PRETTY_PRINTER}
  50.  
  51.    c_define is
  52.       require
  53.      small_eiffel.is_ready
  54.       local
  55.      i: INTEGER;
  56.       do
  57.      from
  58.         i := 1;
  59.      until
  60.         i > manifest_array_types.count
  61.      loop
  62.         c_define_for(manifest_array_types.item(i));
  63.         i := i + 1;
  64.      end;
  65.       end;
  66.  
  67. feature {NONE}
  68.  
  69.    c_define_for(ma_type: TYPE) is
  70.       local
  71.      ma_id, elt_id: INTEGER;
  72.      elt_type: TYPE;
  73.       do
  74.      ma_id := ma_type.id;
  75.      elt_type := ma_type.generic_list.item(1).run_type;
  76.      elt_id := elt_type.id;
  77.      -- Prepare header :
  78.      header.copy(fz_void);
  79.      header.extend('*');
  80.      header.append(us_se_ma);
  81.      ma_id.append_in(header);
  82.      header.append("(int argc,...)");
  83.      -- Prepare body :
  84.      body.clear;
  85.      body.extend('T');
  86.      ma_id.append_in(body);
  87.      body.append("*m;%N%
  88.              %va_list pa;%N");
  89.      if elt_type.is_reference then
  90.         body.append(fz_t0_star);
  91.      else         
  92.         body.extend('T');
  93.         elt_id.append_in(body);
  94.      end;
  95.      body.append("*s;%N%
  96.              %m=");
  97.      if gc_handler.is_on then
  98.         body.append(fz_new);
  99.         ma_id.append_in(body);
  100.         body.extend('(');
  101.         body.extend(')');
  102.         body.append(fz_00);
  103.      else
  104.         body.append(us_malloc);
  105.         body.extend('(');
  106.         body.append(fz_sizeof);
  107.         body.extend('(');
  108.         body.extend('*');
  109.         body.extend('m');
  110.         body.extend(')');
  111.         body.extend(')');
  112.         body.append(fz_00);
  113.         body.extend('*');
  114.         body.extend('m');
  115.         body.extend('=');
  116.         body.extend('M');
  117.         ma_id.append_in(body);
  118.         body.append(fz_00);
  119.      end;
  120.      body.append(
  121.            "if(argc){%N%
  122.        %s=malloc(argc*sizeof(*s));%N%
  123.        %m->_storage=s;%N%
  124.        %m->_capacity=argc;%N%
  125.        %m->_lower=1;%N%
  126.        %m->_upper=argc;%N%
  127.        %va_start(pa,argc);%N%
  128.        %while(argc--){%N");
  129.      if (elt_type.is_integer or else 
  130.          elt_type.is_boolean or else 
  131.          elt_type.is_character) 
  132.       then
  133.            body.append("*(s++)=va_arg(pa,int);%N");
  134.      elseif elt_type.is_real or else elt_type.is_double then
  135.            body.append("*(s++)=va_arg(pa,double);%N");
  136.      elseif elt_type.is_user_expanded then
  137.         body.append(
  138.              "memcpy(*((char**)va_arg(pa,T0*)),s++,size_of(*s));%N");
  139.      else
  140.         body.append("*(s++)=((void*)(va_arg(pa,char*)));%N");
  141.      end;
  142.      body.append("}%N%
  143.              %va_end(pa);%N}%N%
  144.              %return m;");
  145.      -- 
  146.      cpp.put_c_function(header,body);
  147.       end;
  148.  
  149. feature {NONE}
  150.  
  151.    header: STRING is
  152.       once
  153.      !!Result.make(64);
  154.       end;
  155.  
  156.    body: STRING is
  157.       once
  158.      !!Result.make(1024);
  159.       end;
  160.  
  161. end -- MANIFEST_ARRAY_POOL
  162.  
  163.